package com.bupt.kgplatform.common;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://10.112.239.245:3306/kgplatform?allowMultiQuires=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true&allowPublicKeyRetrieval=true", "root", "root")
                .globalConfig(builder -> {
                    builder.author("zhuyunfei") // 设置作者
                           .fileOverride() // 覆盖已生成文件
                           .outputDir("D:\\CodeSpace\\kgplatform\\kgplatform\\src\\main\\java"); // 指定输出目录
                })
                .templateConfig(builder -> {builder.controller("");})//不生成controller
                .packageConfig(builder -> {
                    builder.parent("com.bupt") // 设置父包名
                            .moduleName("kgplatform") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\CodeSpace\\kgplatform\\kgplatform\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("material")// 设置需要生成的表名
                            .addTablePrefix("t_", "c_")//数据库前缀过滤
                            .entityBuilder().enableLombok()
                            .serviceBuilder().formatServiceFileName("%sService");
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }
}
